package com.srd.phone.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.android.volley.VolleyError;
import com.shengrongdai.srd.R;
import com.srd.phone.mvp.presenters.UtilPresenter;
import com.srd.phone.utils.Constants;
import com.srd.phone.utils.UserUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 修改登录密码
 */
public class SafeUpdateLoginPwdActivity extends BaseActivity implements View.OnClickListener {

    private EditText et_old, et_new, et_sure;
    private Button bt_commit;
    private UtilPresenter utilPresenter = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_safe_update_login_pwd);
        initView();
        initData();
    }

    @Override
    public void initView() {
        super.initView();
        tv_common_title.setText("修改登录密码");
        et_old = (EditText) findViewById(R.id.et_old);
        et_new = (EditText) findViewById(R.id.et_new);
        et_sure = (EditText) findViewById(R.id.et_sure);
        bt_commit = (Button) findViewById(R.id.bt_commit);
        bt_commit.setOnClickListener(this);
    }

    @Override
    public void initData() {
        super.initData();

        presenter = new UtilPresenter(requestQueue, this);
        utilPresenter = (UtilPresenter)presenter;
        setUrlArrs(Constants.RESET_PW);

    }

    @Override
    public void returnData(String tag, String data) {
        super.returnData(tag, data);
        if(Constants.RESET_PW.equals(tag)){

        }
    }

    @Override
    public void onError(String tag, VolleyError error) {
        super.onError(tag, error);
    }


    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.bt_commit:

                String oldStr = et_old.getText().toString().trim();
                String newStr = et_new.getText().toString().trim();
                String sureStr = et_sure.getText().toString().trim();

                if(TextUtils.isEmpty(oldStr)){
                    toastShow("旧密码不能为空~");
                    return;
                }else if(TextUtils.isEmpty(newStr)){
                    toastShow("新密码不能为空~");
                    return;
                }else if(!newStr.equals(sureStr)){
                    toastShow("密码输入不一致~");
                    return;
                }

                Map<String, String> map = new HashMap<>();
                map.put("oPwd", oldStr);
                map.put("nPwd", newStr);
                map.put("t", UserUtils.getUserInfo().ticket);
//                map.put("t", "3cf12f78-0874-43c1-8666-d6f834aa2fc7");

                utilPresenter.mapParams(Constants.RESET_PW, map);

                break;
        }

    }

}
